from pydantic import RedisDsn
from pydantic_settings import BaseSettings
from functools import lru_cache


class AppConfigSettings(BaseSettings):
    """应用配置"""
    APP_ENV: str = "dev"
    APP_NAME: str = "fastapi-test"
    APP_PORT: int = 8080
    APP_HOST: str = '127.0.0.1'
    APP_VERSION: str = '1.0'
    APP_DEBUG: bool = False

    """jwt配置"""
    JWT_ENABLE: bool = False
    JWT_SECRET_KEY: str = "suhan@qq.com"
    JWT_ALGORITHM: str = "HS256"
    JWT_EXPIRED: int = 8
    JWT_ISS: str = "SuHan"

    """数据库配置"""
    DB_HOST: str
    DB_PORT: int
    DB_USER: str
    DB_PASSWORD: str
    DB_DATABASE: str

    """redis配置"""
    REDIS_DSN: str

    class Config:
        env_file = ".env"


@lru_cache()
def get_setting()->AppConfigSettings:
    """获取配置"""
    return AppConfigSettings()


setting = get_setting()

